import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import '@/permission'
import { refreshAsyncRouter } from '@/router'
import pinia from '@/stores/index'
import { useUserStore } from '@/stores/index'
import '@/assets/main.scss'
// svg插件配置代码
import 'virtual:svg-icons-register'
import globalComponent from '@/icons/index'

console.log('进入main.ts')

const app = createApp(App)
app.use(pinia)
// 刷新后，初始化动态路由，再应用路由
refreshAsyncRouter()
app.use(router)

// 注册自定义指令，控制功能权限
app.directive('permission', (el, binding) => {
  // el是当前指令作用的dom元素对象
  // binding 是 v-permission=“表达式” 表达式信息
  // console.log(el)
  console.log(binding)
  const userStore = useUserStore()
  const points = userStore.user.roles?.ponits || []
  // ponits 是否有add-employee权限
  if (!points.includes(binding.value)) {
    // 删除或禁用
    el.remove()
    // el.disabled = true
  }
})

app.use(globalComponent)

app.mount('#app')
